﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;
using models;
using DAL;
using System.Data.SqlClient;

namespace BLL
{
   public class OrderManager
    {
        OrderService service = new OrderService();
        //获取订单详情
       public List<Order> GetOrder()
        {
            List<Order> orderList = new List<Order>();
            SqlDataReader reader = service.selectOrder();
            while (reader.Read())
            {
                orderList.Add(
                    new Order(
                        reader.GetInt32(0),
                        reader.GetString(1),
                        reader.GetDateTime(2),
                        reader.GetInt32(3),
                        reader.GetInt32(4)
                        )
                    );
            }
            DBhelper.Close();
            return orderList;
        }
        //生成订单
        public bool InsertOrders(Order order)
        {
            return service.InsertOrder(order);
        }
        //根据id获取订单详情
        public List<Order> GetOrderid(int id)
        {
            List<Order> orderList = new List<Order>();
            SqlDataReader reader = service.selectOrderid(id);
            while (reader.Read())
            {
                orderList.Add(
                    new Order(
                        reader.GetInt32(0),
                        reader.GetString(1),
                        reader.GetDateTime(2),
                        reader.GetInt32(3),
                        reader.GetInt32(4)
                        )
                    );
            }
            DBhelper.Close();
            return orderList;
        }
        //删除订单
        public bool DeleteOrders(int id)
        {
            return service.DeleteOrder(id);
        }
        //个人中心订单详情显示
       // public List<>

        //订单详细信息
        public List<ddxq> GetOrderss(int id)
        {
            List<ddxq> ordersList = new List<ddxq>();
            SqlDataReader reader = service.selectorders(id);
            while (reader.Read())
            {
                ordersList.Add(
                    new ddxq(
                        reader.GetString(0),
                        reader.GetString(1),
                        
                        reader.GetString(2)
                       

                        ));

            }
                 DBhelper.Close();
                return ordersList;
        }
        //订单详细信息 带筛选
        //public List<ddxq> GetOrderss(int id,int state)
        //{
        //    List<ddxq> ordersList = new List<ddxq>();
        //    SqlDataReader reader = service.selectorders(id,state);
        //    while (reader.Read())
        //    {
        //        ordersList.Add(
        //            new ddxq(
        //                reader.GetInt32(0),
        //                reader.GetString(1)
        //                ));

        //    }
        //    DBhelper.Close();
        //    return ordersList;
        //}
        //根据订单状态查询订单详细信息
        public List<ddxq> GetOrderssstate(int id,int state)
        {
            List<ddxq> ordersList = new List<ddxq>();
            SqlDataReader reader = service.selectordersstate(id,state);
            while (reader.Read())
            {
                ordersList.Add(
                    new ddxq(
                  reader.GetString(0),
                        reader.GetString(1),
                
                 reader.GetString(2)

                        ));

            }
            DBhelper.Close();
            return ordersList;
        }
        //根据订单号删除订单
        public bool DeleteOrdersss(string order)
        {
            return service.DeleteOrderss(order);
        }


        //根据订单号查询商品详细信息
        public List<ddxq> GetOrde(string order)
        {
            List<ddxq> ordersList = new List<ddxq>();
            SqlDataReader reader = service.selectorde(order);
            while (reader.Read())
            {
                ordersList.Add(
                    new ddxq(
                        reader.GetString(0),
                        reader.GetString(1),
                        reader.GetString(2),
                        reader.GetString(3),
                        reader.GetString(4),
                        reader.GetDecimal(5),
                        reader.GetInt32(6),
                        reader.GetInt32(7),
                        reader.GetDecimal(8),
                        reader.GetString(9)

                        ));

            }
            DBhelper.Close();
            return ordersList;
        }

        //修改订单状态
        //public bool updateOrder(Order order)
        //{
        //    return service.updateorder(order);
        //}
        //查询订单总价
        public List<ddxq> GetSUM(string order)
        {
            List<ddxq> ordersList = new List<ddxq>();
            SqlDataReader reader = service.selectsum(order);
            while (reader.Read())
            {
                ordersList.Add(
                    new ddxq(
                       
                        reader.GetDecimal(0)
                       

                        ));

            }
            DBhelper.Close();
            return ordersList;
        }
        public bool UporderByIdIsState(string ddh) 
        {
            return service.UporderByIdIsState(ddh);
        }

        public bool updateByidsta(string orders)
        {
            return service.updataByidState(orders);
        }
    }
}
